/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[TestComparator.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package collections;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * 集合框架 - java.util.Comparator
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class TestComparator {

	private int id;
	private String name;

	@Override
	public String toString() {
		return "TestComparator [id=" + id + ", name=" + name + "]";
	}

	public static void main(String[] args) {
		TestComparator tc1 = new TestComparator();
		tc1.id = 1;
		tc1.name = "Yang";

		TestComparator tc2 = new TestComparator();
		tc2.id = 2;
		tc2.name = "Sean";

		// 为TreeSet指定比较器
		TreeSet<TestComparator> set = new TreeSet<>(new Comparator<TestComparator>() {
			@Override
			public int compare(TestComparator o1, TestComparator o2) {
				return o1.name.compareTo(o2.name);
			}
		});

		set.add(tc1);
		set.add(tc2);

		System.out.println(set);
	}
}
